#!/usr/bin/env python
# _*_ coding:utf-8 _*_


import logging
import sys
import requests

from ..platform import ManageProcessor,Color

logging.basicConfig(filename='Weblogic.log',
                    format='%(asctime)s %(message)s',
                    filemode="w", level=logging.INFO)

headers = {'user-agent': 'ceshi/0.0.1'}


@ManageProcessor.plugin_register('SSRF')
class SSRF(object):
    def process(self,ip,port):
        self.run(ip,port)

    def islive(self,ur,port):
        url='http://' + str(ur)+':'+str(port)+'/uddiexplorer/'
        r = requests.get(url, headers=headers)
        return r.status_code

    def run(self,url,port):
        if self.islive(url,port)==200:
            u='http://' + str(url)+':'+str(port)+'/uddiexplorer/'
            logging.info('[+]The target Weblogic UDDI module is exposed! The path is: {} Please verify the SSRF vulnerability!'.format(u))
            print(Color.OKBLUE+'[+]The target Weblogic UDDI module is exposed!\n[+]The path is: {}\n[+]Please verify the SSRF vulnerability!'.format(u)+Color.ENDC)
            print(Color.OKGREEN+'[+]SSRF 漏洞存在'+Color.ENDC)
        else:
            logging.info("[-]The target Weblogic UDDI module default path does not exist!")
            print(Color.FAIL+"[-]The target Weblogic UDDI module default path does not exist!"+Color.ENDC)